//
//  XKTradeHeaderCell.m
//  XKJY
//
//  Created by xuyaguang on 2017/1/13.
//  Copyright © 2017年 xiaokang100. All rights reserved.
//

#import "XKTradeHeaderCell.h"

@interface XKTradeHeaderCell ()

// 标题
@property (nonatomic, strong) UILabel *wopTitleLabelOne; // 可用
@property (nonatomic, strong) UILabel *wopTitleLabelTwo; // 冻结
@property (nonatomic, strong) UILabel *wopTitleLabelThree; // 总共
// 数值
@property (nonatomic, strong) UILabel *wopCountLabelOne;
@property (nonatomic, strong) UILabel *wopCountLabelTwo;
@property (nonatomic, strong) UILabel *wopCountLabelThree;

// 人民币资产
// 标题
@property (nonatomic, strong) UILabel *rmbTitleLabelOne; // 可用
@property (nonatomic, strong) UILabel *rmbTitleLabelTwo; // 冻结
@property (nonatomic, strong) UILabel *rmbTitleLabelThree; // 总共
// 数量
@property (nonatomic, strong) UILabel *rmbCountLabelOne;
@property (nonatomic, strong) UILabel *rmbCountLabelTwo;
@property (nonatomic, strong) UILabel *rmbCountLabelThree;

// 分割线
@property (nonatomic, strong) UILabel *lineOne;
@property (nonatomic, strong) UILabel *lineTwo;
@property (nonatomic, strong) UILabel *lineThree;
@property (nonatomic, strong) UILabel *lineFour;
@property (nonatomic, strong) UILabel *lineCentr;
@property (nonatomic, strong) UILabel *lineTop;

@property(nonatomic, strong) NSMutableArray<UILabel *> *lineArrayM;
@property(nonatomic, strong) NSMutableArray<UILabel *> *titleArrayM;
@property(nonatomic, strong) NSMutableArray<UILabel *> *countArrayM;

@end
@implementation XKTradeHeaderCell

#pragma mark - 自定义cell重写构造方法
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self configArguments];
        [self createSubviews];
    }
    return self;
}

#pragma mark - 设置自身
- (void)configArguments {
    self.backgroundColor = WhiteColor;
    self.selectionStyle = UITableViewCellSelectionStyleNone;
}

#pragma mark - 创建控件
- (void)createSubviews {
    
    _lineTop = [UILabel new];
    _lineTop.backgroundColor = kBaseGrayColor;
    
    _lineCentr = [UILabel new];
    _lineCentr.backgroundColor = kBaseGrayColor;
    
    _lineOne = [UILabel new];
    _lineOne.backgroundColor = kBaseGrayColor;
    
    _lineTwo = [UILabel new];
    _lineTwo.backgroundColor = kBaseGrayColor;
    
    _lineThree = [UILabel new];
    _lineThree.backgroundColor = kBaseGrayColor;
    
    _lineFour = [UILabel new];
    _lineFour.backgroundColor = kBaseGrayColor;
    
    
    _wopTitleLabelOne = [UILabel getLabWithText:@"WOS可用(¥)" textFont:Font_14 textColor:UIColorFromRGB(0x999999) textAlignment:NSTextAlignmentCenter];
    _wopTitleLabelTwo = [UILabel getLabWithText:@"冻结(¥)" textFont:Font_14 textColor:UIColorFromRGB(0x999999) textAlignment:NSTextAlignmentCenter];
    _wopTitleLabelThree= [UILabel getLabWithText:@"总资产(¥)" textFont:Font_14 textColor:UIColorFromRGB(0x999999) textAlignment:NSTextAlignmentCenter];
    _rmbTitleLabelOne = [UILabel getLabWithText:@"人民币可用(¥)" textFont:Font_14 textColor:UIColorFromRGB(0x999999) textAlignment:NSTextAlignmentCenter];
    _rmbTitleLabelTwo = [UILabel getLabWithText:@"冻结(¥)" textFont:Font_14 textColor:UIColorFromRGB(0x999999) textAlignment:NSTextAlignmentCenter];
    _rmbTitleLabelThree = [UILabel getLabWithText:@"总资产(¥)" textFont:Font_14 textColor:UIColorFromRGB(0x999999) textAlignment:NSTextAlignmentCenter];
    
    
    _wopCountLabelOne = [UILabel getLabWithText:@"0.00" textFont:Font_14 textColor:UIColorFromRGB(0x333333) textAlignment:NSTextAlignmentCenter];
    _wopCountLabelTwo = [UILabel getLabWithText:@"0.00" textFont:Font_14 textColor:UIColorFromRGB(0x333333) textAlignment:NSTextAlignmentCenter];
    _wopCountLabelThree = [UILabel getLabWithText:@"0.00" textFont:Font_14 textColor:UIColorFromRGB(0x333333)  textAlignment:NSTextAlignmentCenter];
    _rmbCountLabelOne = [UILabel getLabWithText:@"0.00" textFont:Font_14 textColor:UIColorFromRGB(0x333333)  textAlignment:NSTextAlignmentCenter];
    _rmbCountLabelTwo = [UILabel getLabWithText:@"0.00" textFont:Font_14 textColor:UIColorFromRGB(0x333333)  textAlignment:NSTextAlignmentCenter];
    _rmbCountLabelThree = [UILabel getLabWithText:@"0.00" textFont:Font_15 textColor:UIColorFromRGB(0x333333) textAlignment:NSTextAlignmentCenter];
    
    [self.contentView addSubview:_lineOne];
    [self.contentView addSubview:_lineTwo];
    [self.contentView addSubview:_lineThree];
    [self.contentView addSubview:_lineFour];
    [self.contentView addSubview:_lineTop];
    [self.contentView addSubview:_lineCentr];
    
    [self.contentView addSubview:_wopTitleLabelOne];
    [self.contentView addSubview:_wopTitleLabelTwo];
    [self.contentView addSubview:_wopTitleLabelThree];
    [self.contentView addSubview:_wopCountLabelOne];
    [self.contentView addSubview:_wopCountLabelTwo];
    [self.contentView addSubview:_wopCountLabelThree];
    
    [self.contentView addSubview:_rmbTitleLabelOne];
    [self.contentView addSubview:_rmbTitleLabelTwo];
    [self.contentView addSubview:_rmbTitleLabelThree];
    [self.contentView addSubview:_rmbCountLabelOne];
    [self.contentView addSubview:_rmbCountLabelTwo];
    [self.contentView addSubview:_rmbCountLabelThree];
    
    [self.lineArrayM addObjectsFromArray:@[_lineOne, _lineTwo, _lineThree, _lineFour]];
    
    [self.titleArrayM addObjectsFromArray:@[_wopTitleLabelOne, _wopTitleLabelTwo, _wopTitleLabelThree, _rmbTitleLabelOne, _rmbTitleLabelTwo, _rmbTitleLabelThree]];
    
    [self.countArrayM addObjectsFromArray:@[_wopCountLabelOne, _wopCountLabelTwo, _wopCountLabelThree, _rmbCountLabelOne, _rmbCountLabelTwo, _rmbCountLabelThree]];
    
    
    [self addConstraints];
    
}
#pragma mark - 添加约束
- (void)addConstraints {
    
    [self.lineTop mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.top.mas_equalTo(self.contentView);
        make.height.mas_equalTo(5*Scale_H);
    }];
    

    for (NSInteger i = 0; i < self.lineArrayM.count; i++) {
        [self.lineArrayM[i] mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.mas_equalTo(self.contentView.mas_left).offset((Main_Width/3)*(i%2) + (Main_Width/3));
            make.top.mas_equalTo(self.lineTop.mas_bottom).offset(10*Scale_H + (30 + 30)*Scale_H*(i/2));
            make.width.mas_equalTo(1*Scale_W);
            make.height.mas_equalTo(40*Scale_H);
            if (i == self.lineArrayM.count - 1) {
                make.bottom.mas_equalTo(self.contentView).offset(-10*Scale_H).priorityHigh();
            }
        }];
    }
    
    for (NSInteger i = 0; i < self.titleArrayM.count; i++) {
        [self.titleArrayM[i] mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.mas_equalTo(self.contentView.mas_left).offset((Main_Width/3)*(i%3) + (Main_Width/6));
            make.top.mas_equalTo(self.lineTop.mas_bottom).offset(10*Scale_H + (30 + 30)*Scale_H*(i/3));
        }];
        [self.countArrayM[i] mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.mas_equalTo(self.contentView.mas_left).offset((Main_Width/3)*(i%3) + (Main_Width/6));
            make.top.mas_equalTo(self.lineTop.mas_bottom).offset(30*Scale_H + (30 + 30)*Scale_H*(i/3));
        }];
    }
    
    
    [self.lineCentr mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(self.contentView);
        make.centerY.mas_equalTo(self.contentView).offset(2.5*Scale_H);
        make.height.mas_equalTo(1*Scale_H);
    }];
    
}

- (NSMutableArray<UILabel *> *)lineArrayM {
    if (!_lineArrayM) {
        _lineArrayM = [NSMutableArray array];
    }
    return _lineArrayM;
}

- (NSMutableArray<UILabel *> *)titleArrayM {
    if (!_titleArrayM) {
        _titleArrayM = [NSMutableArray array];
    }
    return _titleArrayM;
}

- (NSMutableArray<UILabel *> *)countArrayM {
    if (!_countArrayM) {
        _countArrayM = [NSMutableArray array];
    }
    return _countArrayM;
}

- (void)setCurrencyModel:(XKUserCurrencyModel *)currencyModel {
    _currencyModel = currencyModel;
    
    self.wopCountLabelTwo.text = [NSString changeNumberFormat:NSNumberFormatterDecimalStyle withNumber:currencyModel.wopforzen_num];
    self.wopCountLabelOne.text = [NSString changeNumberFormat:NSNumberFormatterDecimalStyle withNumber:currencyModel.wopnum];
    

    NSString *wopCountLabelThree_temp = [NSString calculateNumberOne:currencyModel.wopnum calculateType:CalculateType_Add numberTwo:currencyModel.wopforzen_num withMode:NSRoundPlain scale:2];
    self.wopCountLabelThree.text = [NSString changeNumberFormat:NSNumberFormatterDecimalStyle withNumber:wopCountLabelThree_temp];
    
    
    self.rmbCountLabelOne.text = [NSString changeNumberFormat:currencyModel.rmbnum];
    self.rmbCountLabelTwo.text = [NSString changeNumberFormat:currencyModel.rmbforzen_num];

    
    NSString *rmbCountLabelThree_temp = [NSString calculateNumberOne:currencyModel.rmbnum calculateType:CalculateType_Add numberTwo:currencyModel.rmbforzen_num withMode:NSRoundPlain scale:2];
    self.rmbCountLabelThree.text = [NSString changeNumberFormat:rmbCountLabelThree_temp];
}

@end
